﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Malu.WebTemplates;
using MaLu.Common;
using System.Text;
using System.Data;
using MaLu.BusiLogic;

namespace MaluJg.web.Three
{
    public partial class ThreeList : ThreePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ShowAdvancedSearch = false;
            this.ShowUDLayoutButton = false;
            this.ShowLRLayoutButton = false;
            this.ShowSimpleLayoutButton = false;
            this.UseTabber = false;
            this.ShowAdvancedSearch = true;
            this.Title = "事项列表";
        }

        public string SearchDefaultText
        {
            get
            {
                return string.Empty;
            }
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

            Dictionary<string, string> dictWhere = new Dictionary<string, string>();
            string where = "DeptID='" + CurrentUser.MainDepartmentID + "'";
            if (IsLeader)
                where = "1=1";
            if (tbSearch.Text.Trim() != string.Empty && tbSearch.Text.Trim() != SearchDefaultText)
            {
                where+=" and deptdspname like '%"+ tbSearch.Text.Trim().Replace("'", "''")+"%'";
            }



            SearchClause = where;
            Pager.PageIndex = 0;
            BindData();
        }
        protected void btnAdvancedSearch_Click(object sender, EventArgs e)
        {

            string where = "DeptID='" + CurrentUser.MainDepartmentID + "'";
            if (IsLeader)
                where = "1=1";
            if (tbSearch.Text.Trim() != string.Empty && tbSearch.Text.Trim() != SearchDefaultText)
            {
                where += " and deptdspname like '%" + tbSearch.Text.Trim().Replace("'", "''") + "%'";
            }
            if (tbStart.Text != string.Empty)
            {
                where += " and createtime >='" + tbStart.Text + "'";
            }
            if (tbEnd.Text != string.Empty)
            {
                where += " and createtime <'" + DateTime.Parse( tbEnd.Text).AddDays(1) + "'";

            }


            SearchClause = where;
            Pager.PageIndex = 0;
            BindData();
        }
        private void BindData()
        {

            int recordcount = 0;
            DataTable DTMyProposal = BLCommon.GetPagingList(Provider, "ID,DeptDspName,ReportTime,Status,CreateTime", "TEvent1", SearchClause, "CreateTime desc", Pager.PageIndex + 1, Pager.PageSize, false, 0, ref recordcount);
           
            DTMyProposal.Columns.Add("StatusName");
            foreach (DataRow dr in DTMyProposal.Rows)
            {
                if (dr["Status"].ToString() == ((int)MaLu.Common.Const.EventStatus.已提交).ToString())
                {
                    dr["StatusName"] = MaLu.Common.Const.EventStatus.已提交.ToString();
                }
                if (dr["Status"].ToString() == ((int)MaLu.Common.Const.EventStatus.已审阅).ToString())
                {
                    dr["StatusName"] = MaLu.Common.Const.EventStatus.已审阅.ToString();
                }
            }
            Pager.RecordCount = recordcount;
            rptProposal.DataSource = DTMyProposal;
            rptProposal.DataBind();
        }
        protected override void Order_OrderChanged(object sender, EventArgs e)
        {
            BindData();
            base.Order_OrderChanged(sender, e);
        }
        protected override void Pager_PageChanged(object sender, EventArgs e)
        {
            BindData();
            base.Pager_PageChanged(sender, e);
        }
        public string SearchClause
        {
            get
            {
                if (ViewState["SearchClause"] == null)
                {
                    if (IsLeader)
                    {
                        ViewState["SearchClause"] = "1=1";
                    }
                    else
                    ViewState["SearchClause"] = "DeptID='" +CurrentUser.MainDepartmentID+"'";

                }
                return ViewState["SearchClause"].ToString();
            }
            set
            {
                ViewState["SearchClause"] = value;
            }
        }
    }
}
